package com.jandar.controller;

import com.jandar.service.AnalyzeService;
import com.jandar.service.BankService;
import com.jandar.service.BillService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/analyzeAndStatistics")
public class BillController {
    @Autowired
    BillService billService;
    @Autowired
    BankService bankService;
    @Autowired
    AnalyzeService analyzeService;

    @RequestMapping("generateAddress")
    public ResponseEntity generateAddress() {
        billService.generateAddress();
        return ResponseEntity.ok("地址生成任务提交成功");
    }


    @RequestMapping("upload")
    public ResponseEntity uploadFile(MultipartFile file, String bankName, HttpServletRequest request) {
        analyzeService.uploadFile(file,null,null,"",request);
        return ResponseEntity.ok("上传成功");
    }

    @PostMapping("page")
    public ResponseEntity page(@RequestBody AnalyzeService.PageParam pageParam, HttpServletRequest request) {
        pageParam.setTypeName("话单,通话");
        return ResponseEntity.ok(analyzeService.page(pageParam, request));
    }

    @PostMapping("pageBySheetName")
    public ResponseEntity pageBySheetName(@RequestBody BillService.PageParam pageParam) {
        return ResponseEntity.ok(billService.pageBySheet(pageParam));
    }

    @GetMapping("listSheetName")
    public ResponseEntity listSheetName() {
        return ResponseEntity.ok(billService.listSheetName());
    }

    @GetMapping("delete")
    public ResponseEntity delete(Integer id) {
        return ResponseEntity.ok(analyzeService.delete(id));
    }

//
//    @PostMapping("processDataApi")
//    public ResponseEntity processBillDataApi(@RequestBody ProcessDataApiParam param) {
//        if (param.tag.contains("话单分析")) {
//            billService.processBankDataApi(param.data, param.mappingList);
//        } else if (param.tag.contains("账单分析")) {
//            bankService.processBankDataApi(param.data, param.mappingList);
//        }
//        return ResponseEntity.ok("success");
//    }

    @Data
    static class ProcessDataApiParam {
        List<Map> data;
        List<Map<String, Object>> mappingList;
        String tag;
    }

}
